//
//  ViewController.m
//  timemovie
//
//  Created by Yiqiao on 15/7/17.
//  Copyright (c) 2015年 Yiqiao. All rights reserved.
//

#import "ViewController.h"
#import "buttonself.h"
#import "moreViewController.h"
#import "NewsViewController.h"
#import "movieViewController.h"
#import "topViewController.h"
#import "theaterViewController.h"
#import "baseNavController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)createViewc{
    
    moreViewController *mvc = [[moreViewController alloc]init];
    NewsViewController *nvc = [[NewsViewController alloc ]init ];
    topViewController *tvc = [[topViewController alloc]init];
    movieViewController *movc = [[movieViewController alloc]init];
    theaterViewController *thvc = [[theaterViewController alloc]init];
    
    NSArray *vcArray = @[movc,nvc,tvc,thvc,mvc];
    NSMutableArray *navArray =[[NSMutableArray alloc]init];
    
    for (int i= 0; i<5; i++) {
        baseNavController *nav = [[baseNavController alloc]initWithRootViewController:vcArray[i]];
        [navArray addObject:nav];
    }
    
    self.viewControllers = navArray;
    
}

- (void)seTTabbar{
    
    Class cls = NSClassFromString(@"UITabBarButton");
    
    for (UIView *subView in self.tabBar.subviews) {
        if ([subView isKindOfClass:cls]) {
            [subView removeFromSuperview];
        }
    }
    
    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_bg_all"]];
    CGFloat width = CGRectGetWidth(self.tabBar.frame)/5;
    CGFloat height = CGRectGetHeight(self.tabBar.frame);
    NSArray *titleArray = @[@"movies",@"news",@"top",@"theatre",@"more"];
    NSArray *imageName = @[@"movie_home",@"msg_select_new",@"start_top250",@"icon_cinema",@"more_setting"];
    _select = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    _select.image = [UIImage imageNamed:@"selectTabbar_bg_all"];
    [self.tabBar addSubview:_select];
    
    for ( int i=0; i<5; i++) {
        
        CGRect frame = CGRectMake(i*width, 0, width, height);
        buttonself *button = [[buttonself alloc]initWithFrame:frame withImageName:imageName[i] withTitle:titleArray[i]];
        button.tag = i;
        [button addTarget:self action:@selector(btuAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.tabBar addSubview:button];
        
    }
    
}
- (void)btuAction:(buttonself *)button{
    
    NSInteger index = button.tag;
    self.selectedIndex = index;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    _select.center = button.center;
    [UIView commitAnimations];

}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self createViewc];
    [self seTTabbar];
   // [self preferredStatusBarStyle];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
